package com.maweirdos.ai.config;

import com.maweirdos.ai.mapper.ChatMessageMapper;
import com.maweirdos.ai.core.memory.storage.DatabaseChatMemory;
import com.maweirdos.ai.core.memory.DatabaseChatMemoryRepository;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 聊天记忆配置类
 * 注册数据库持久化的聊天记忆组件
 */
@Configuration
public class ChatMemoryConfig {

    /**
     * 注册数据库聊天记忆存储库
     */
    @Bean
    public ChatMemoryRepository chatMemoryRepository(ChatMessageMapper chatMessageMapper) {
        return new DatabaseChatMemoryRepository(chatMessageMapper);
    }

    /**
     * 注册数据库聊天记忆
     */
    @Bean
    public ChatMemory chatMemory(ChatMessageMapper chatMessageMapper, DatabaseChatMemoryRepository repository) {
        return new DatabaseChatMemory(chatMessageMapper, repository);
    }
} 